#include "lcd.h"
#include "emboard.h"

LcdDialog::LcdDialog(QWidget * parent, Qt::WindowFlags f)
    : QDialog(parent, f)
{
    mTimer = new QTimer(this);
    connect(mTimer, SIGNAL(timeout()), this, SLOT(update()));
    mImg = NULL;
}

LcdDialog::~LcdDialog()
{
}

void LcdDialog::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    unsigned char* addr = em_get_lcd_base_addr();

    QImage *img = NULL;
    if (addr == 0) {
        img = new QImage(240, 320, QImage::Format_RGB32);
        img->fill(0);
    } else {
        img = new QImage(reinterpret_cast<const unsigned char*>(addr), 240, 320, QImage::Format_RGB32);
    }
    painter.drawPixmap(0, 0, QPixmap::fromImage(*img));
    delete img;
}

void LcdDialog::startSync()
{
    mTimer->start(20);
}

void LcdDialog::setImage(QImage *img)
{
    mImg = img;
}
